package com.design.designmode.action.vistor;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hxl
 * @since 2023-04-18
 */
public class PersonStructure {
    private List<Person> personList = new ArrayList<Person>();

    public PersonStructure() {
        personList.add(new Student("张三", 20, 70));
        personList.add(new Student("李四", 21, 80));
        personList.add(new Student("王五", 22, 90));

        personList.add(new Teacher("李老师", 26, 3));
        personList.add(new Teacher("陈老师", 27, 4));
        personList.add(new Teacher("刘老师", 28, 5));
    }

    public void accept(Visitor visitor) {
        // for (遍历对象类型 对象名 : 遍历对象)
        for (Person person : personList) {
            person.accept(visitor);
        }
    }

}
